﻿--9 --	Найти всех бабушек

SELECT DISTINCT [ID], [LastName], [Name], [fk_motherID]
from [MyFamily].[dbo].[Persons]
where [ID] in
(
SELECT DISTINCT A1.[fk_motherID]
from [MyFamily].[dbo].[Persons] as A1, [MyFamily].[dbo].[Persons] as A2
where ((A1.ID = A2.fk_fatherID) and (A1.fk_fatherID is not null))
union
SELECT DISTINCT A1.[fk_motherID]
from [MyFamily].[dbo].[Persons] as A1, [MyFamily].[dbo].[Persons] as A2
where ((A1.ID = A2.fk_motherID) and (A1.fk_fatherID is not null))
)  
